package JDBC;

import java.sql.*;

public class ConnectMysql {
    public static Connection getConnectMysql(){
        String url="jdbc:mysql://localhost:3306/javakc?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8";
        String username="root";
        String password="123456";
        Connection connection=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");//加载数据库驱动
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        try {
             connection = DriverManager.getConnection(url,username,password);//创建数据库对象
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
